<?php
/*
 +-------------------------------------------------------------------------+
 | Copyright (C) 2007 The Cacti Group                                      |
 |                                                                         |
 | This program is free software; you can redistribute it and/or           |
 | modify it under the terms of the GNU General Public License             |
 | as published by the Free Software Foundation; either version 2          |
 | of the License, or (at your option) any later version.                  |
 |                                                                         |
 | This program is distributed in the hope that it will be useful,         |
 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
 | GNU General Public License for more details.                            |
 +-------------------------------------------------------------------------+
 | Cacti: The Complete RRDTool-based Graphing Solution                     |
 +-------------------------------------------------------------------------+
 | This code is designed, written, and maintained by the Cacti Group. See  |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/
include_once (dirname(__FILE__) . "/model/nms_setting_model.php");
include_once (dirname(__FILE__) . "/model/nms_alarm_model.php");
include_once(dirname(__FILE__) ."/../../lib/data_query.php");
include_once(dirname(__FILE__) . "/libs/nms_html_scripts.php");
include_once(dirname(__FILE__) . "/libs/nms_html_views.php");
function draw_setting(){

	html_script_reload();
	html_setting_script_reload();

	draw_setting_sound();
	draw_setting_system();
	draw_setting_update_device();
	//check number of sound
	function checknSound(){
		$num = db_fetch_cell('SELECT count(*) from plugin_nms_setting');
		if($num>10){
			return false;
		}
		else{
			return  true;
		}
	}
			function deletesound($id){
				$name = db_fetch_cell('SELECT sound_name FROM plugin_nms_setting
										WHERE sound_id = '.$id.'');
				unlink("plugins/nms/upload/".$name);
				delete_sound($id);
			}
			if(isset($_REQUEST['action'])){
				if($_REQUEST['action'] == 'delete'){
					$id =(int) $_REQUEST['id'];
					deletesound($id);
					echo '<script>
			 			reLoad1();
			 		</script>';
				}
			}
}

?>
<?php
	function draw_setting_sound(){
?>
	<form action="nms.php?run=setting" method ="post"enctype="multipart/form-data">
	
		<div id="id_master_center">
				<div id="id_master_header">
					<h2> Setting Sound </h2>
				</div>
    	<div id="id_setting_center">
	<!---->
			<table width="100%" border="0" id ="dtTable">
								  <tr class="cls_master_table_title" >
								  	<th width ="4%" scope="col"><h3>ID</h3></th>
								    <th width="51%" scope="col"><h3>Sound Name</h3></th>
								    <th width="10%" scope="col"><h3> Interface Down</h3></th>
								    <th width="10%" scope="col"><h3>Interface Up</h3></th>
								    <th width="10%" scope="col"><h3>Device Down</h3></th>
								    <th width="5%" scope="col">&nbsp;</th>
								  </tr>
								  <!-- Get data from setting to show on table -->
								 <?php $sound = db_fetch_assoc('Select sound_id, sound_name , sound_up, sound_down,device_down
		 												from plugin_nms_setting order by sound_id'); ?>
								  <?php 
								  		$stt=0;
								  		foreach($sound as $item){
								  		$stt++;
								  ?>
								  <tr <?php if($stt%2==0) {echo 'class="xanhlot"';}
						 					else {echo 'class="xanhdam"';}?>> 
								    <td><?php echo $stt;?></td>
								    <td><?php echo $item['sound_name']?></td>
								    <td align="center"><input type= "radio" name = "down"<?php if($item['sound_down'] == 1){echo 'checked = "checked"';}?><?php echo 'value ="'.$item['sound_id'].'" ';?>></td>
								    <td align="center"><input type= "radio" name = "up" <?php if($item['sound_up'] == 1){echo 'checked = "checked"';}?><?php echo 'value ="'.$item['sound_id'].'" ';?> ></td>
								    <td align="center"><input type= "radio" name = "ddown" <?php if($item['device_down'] == 1){echo 'checked = "checked"';}?><?php echo 'value ="'.$item['sound_id'].'" ';?> ></td>
								    <td align="center"><a href="nms.php?run=setting&action=delete&id=<?php echo $item['sound_id'];?>"onclick="return confirm('Are you sure you want to delete?')"><?php if($item['sound_id']>3){echo'Delete';}?></a></td>
								  </tr>
								  <?php }?>
			</table>
			<div id="save_setting"><input type = "submit" name = "save" value="Save"></div>
				<div align="center">
						<table>
						<tr>
							<td><div id="uploadfile"></div>
							<input type="file" name="file" id="file" ><br></td>
							<td></td>
						</tr>
						<tr>
							<td align="center"><input type="submit" name="submit" id="Upload" value="Upload" onClick="document.location.reload(true)"></td>
						</tr>
						</table>
    			</div>
		</div>
<?php 
		} 
		function draw_setting_system(){
			?>
		<div id="id_master_header">
			<h2> System Setting </h2>
		</div>	
	    <div id="id_system_center">
	    	<div id="updatedevices">
				<h3><div id="id_host_find">Action: </div></h3>
				<select name= "action"  class="action_go" >
					<option value="Fupdate">First update</option>
					<option value="Iupdate">Update interface information</option>
				 </select>
				 <input type = "submit" name = "update" value ="Update">
			 </div>
	    </div>
			<?php 
		}
		
		function draw_setting_update_device(){
			?>
			<div id="id_master_header">
				<h2>Update Inteface Information </h2>
			</div>	
    		<div id="id_system_center">
			    <div id="id_host_find">
					<table width="100%"  class="updatedevices1">
					<tr>
				<td>
					<h3>Devices:</h3>
				</td>
				<td>
				<select  onchange="val()" class="chosen-select" id="id_host_setting" name="id_host_setting">
					        		<?php 
			     					 $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host where description != 'localhost'order by description,hostname");    
			     					 if (sizeof($hosts) > 0) {
								     foreach($hosts as $set) {
								     echo "<option name='host_id[]'value='" . $set["id"] . "'"; echo ">" . htmlspecialchars($set["name"]) . "</option>\n";
								     }
								     }
			   						?>
		
				 </select>
  					<script type="text/javascript">
						$("#id_host_setting").chosen({
							search_contains: true,
							no_results_text:"Oops, nothing found!"});
 					 </script>
				 </td>
				 <td><input type = "submit" name = "updatedevice" value ="UpdateDevice"></td>
				 </tr>
				 </table>
				 </div>
   		 </div>
	</div>
</form>
			<?php 
		}
		?>